<?php

namespace app\common\model;

use think\facade\Db;
use think\Model;

class Answer extends Model
{
    //自动生成写入时间
    protected $autoWriteTimestamp = true;


    public function edit_answer($where_data,$answer_value)
    {

        $answer = '';
        try {
            $answer = $this->one_answer($where_data);
            $answer->answer = $answer_value;
        }catch (\Exception $exception){
            $answer = new Answer;
            $answer->exercises_id = $where_data['exercises_id'];
            $answer->user_id = $where_data['user_id'];
            $answer->answer = $answer_value;
        }
        return $answer->save();
    }



    public function one_answer($data)
    {

        return $this->where($data)->find();

    }



}